#include "data_holder.h"
#include "board.h"

void Data_holder::saveDefault(void)
{
	  parameter.wheel_diameter = 105;
    parameter.wheel_track = 330;
    parameter.encoder_resolution = 4096;
    parameter.do_pid_interval = 10;
    parameter.kp = 200;
    parameter.ko = 10;
    parameter.ki = 1200;
    parameter.kd = 0;
    parameter.cmd_last_time = 250;
    parameter.max_v_liner_x = 50;
    parameter.max_v_liner_y = 0;
    parameter.max_v_angular_z = 200;
    parameter.imu_type = 69;
		parameter.keyWords = DEFAULT_KEY;
}

void Data_holder::load_parameter(void){
  Board::get()->get_config((unsigned char*)&parameter, sizeof(parameter));
	//if(pa)
	/*
	printf("parameter.keyWords:%x \r\n",parameter.keyWords);
	printf("parameter.imu_type:%d  \r\n",parameter.imu_type);
	printf("parameter.max_v_angular_z:%d \r\n",parameter.max_v_angular_z);
	
	printf("parameter.max_v_liner_y:%d \r\n",parameter.max_v_liner_y);
	printf("parameter.max_v_liner_x:%d \r\n",parameter.max_v_liner_x);
	printf("parameter.cmd_last_time:%d \r\n",parameter.cmd_last_time);
	
	printf("parameter.kd:%d \r\n",parameter.kd);
	printf("parameter.ki:%d \r\n",parameter.ki);
		
	printf("parameter.wheel_diameter:%d \r\n",parameter.wheel_diameter);
	printf("parameter.wheel_track:%d \r\n",parameter.wheel_track);
	printf(" parameter.encoder_resolution:%d \r\n", parameter.encoder_resolution);
	printf("parameter.do_pid_interval:%d \r\n",parameter.do_pid_interval);
	printf("parameter.kp:%d \r\n",parameter.kp);
	printf("parameter.ko:%d \r\n",parameter.ko);
*/
	
	if(parameter.keyWords == DEFAULT_KEY)
	{
		printf("read data from IC flash \r\n");
		return;
	}
	else
	{
		printf("fisrt use parameter\r\n");
		saveDefault();
		save_parameter();
		//Board::get()->set_config((unsigned char*)&parameter, sizeof(parameter));
	}
}

void Data_holder::save_parameter(void){
   Board::get()->set_config((unsigned char*)&parameter, sizeof(parameter));
}
    

